package com.zzyl.nursing.controller;

import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.nursing.domain.NursingProject;
import com.zzyl.nursing.service.INursingProjectService;
import com.zzyl.nursing.vo.NursingProjectVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理项目Controller
 *
 * @author yhnyhn123
 * @date 2025-10-20
 */
@RestController
@RequestMapping("/nursing/project" )
@Tag(name = "护理项目相关接口" )
public class NursingProjectController extends BaseController {
    @Autowired
    private INursingProjectService nursingProjectService;

    /**
     * 查询护理项目列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:project:list')" )
    @GetMapping("/list" )
    @Operation(summary = "查询护理项目列表" )
    public TableDataInfo list(NursingProject nursingProject) {
        startPage();
        List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
        return getDataTable(list);
    }

    /**
     * 导出护理项目列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:project:export')" )
    @Log(title = "护理项目" , businessType = BusinessType.EXPORT)
    @Operation(summary = "导出护理项目列表" )
    @PostMapping("/export" )
    public void export(HttpServletResponse response, NursingProject nursingProject) {
        List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
        ExcelUtil<NursingProject> util = new ExcelUtil<NursingProject>(NursingProject.class);
        util.exportExcel(response, list, "护理项目数据" );
    }

    /**
     * 获取护理项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('nursing:project:query')" )
    @GetMapping("/{id}" )
    @Operation(summary = "获取护理项目详细信息" )
    public R<NursingProject> getInfo(@Schema(title = "护理项目ID" )
                                     @PathVariable("id" ) Long id) {
        return R.ok(nursingProjectService.selectNursingProjectById(id));
    }

    /**
     * 新增护理项目
     */
    @PreAuthorize("@ss.hasPermi('nursing:project:add')" )
    @Log(title = "护理项目" , businessType = BusinessType.INSERT)
    @PostMapping
    @Operation(summary = "新增护理项目" )
    public AjaxResult add(@Schema(title = "护理项目实体" ) @RequestBody NursingProject nursingProject) {
        return toAjax(nursingProjectService.insertNursingProject(nursingProject));
    }

    /**
     * 修改护理项目
     */
    @PreAuthorize("@ss.hasPermi('nursing:project:edit')" )
    @Log(title = "护理项目" , businessType = BusinessType.UPDATE)
    @PutMapping
    @Operation(summary = "修改护理项目" )
    public AjaxResult edit(@Schema(title = "护理项目实体" ) @RequestBody NursingProject nursingProject) {
        return toAjax(nursingProjectService.updateNursingProject(nursingProject));
    }

    /**
     * 删除护理项目
     */
    @PreAuthorize("@ss.hasPermi('nursing:project:remove')" )
    @Log(title = "护理项目" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    @Operation(summary = "删除护理项目" )
    public AjaxResult remove(@Schema(title = "护理项目ID数组" ) @PathVariable Long[] ids) {
        return toAjax(nursingProjectService.deleteNursingProjectByIds(ids));
    }

    /**
     * 查询护理项目列表
     */
    @GetMapping("/all" )
    @Operation(summary = "查询所有护理项目" )
    public AjaxResult listAll() {
        List<NursingProjectVo> list = nursingProjectService.selectAll();
        return success(list);
    }
}
